package com.library.controller;

import com.library.pojo.dto.borrow.BorrowPageQueryDTO;
import com.library.result.PageResult;
import com.library.result.Result;
import com.library.service.BorrowService;
import com.library.service.impl.BorrowServiceImpl;

/**
 * 用户对借阅记录进行操作
 * 只写对外的方法
 */
public class BorrowController {

    BorrowService borrowService = new BorrowServiceImpl();

    /**
     * 分页查询记录
     * @param borrowPageQueryDTO 分页参数（必填：pageNum/pageSize；可选：borrowId/bookId/bookId/borrowTime/returnTime关键词）
     * @return PageResult<UserVO>：分页图书列表
     */
    public Result<PageResult> selectBorrowList(BorrowPageQueryDTO borrowPageQueryDTO) {
        PageResult pageResult = borrowService.pageQuery(borrowPageQueryDTO);
        return Result.success(pageResult);
    }



    /**
     * 根据借阅编号归还图书
     * @param borrowId 借阅Id
     * @return Result<String>：成功/失败提示
     */
    public Result<String> revert(Integer borrowId) {
        int revert = borrowService.revert(borrowId);
        if(revert == 1) {
            return Result.success("还书成功");
        }
        return Result.error("还书失败");
    }
}
